package com.heima.wemedia.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.mapper.WemediaMapper;
import com.heima.wemedia.service.WemediaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class WemediaServiceImpl extends ServiceImpl<WemediaMapper , WmUser> implements WemediaService {
    @Override
    public ResponseResult insert(WmUser wmUser) {
        if(wmUser == null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        wmUser.setCreatedTime(new Date());
        save(wmUser);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    @Override
    public WmUser findByName(String name) {
        LambdaQueryWrapper<WmUser> wrapper = new LambdaQueryWrapper<>();
        if(StringUtils.isNoneBlank(name)){
            LambdaQueryWrapper<WmUser> wrapper1 = wrapper.eq(WmUser::getName, name);
            WmUser user = getOne(wrapper);
            return user;
        }
        return null;
    }
}
